package com.sharelogindemo;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;

/**
 * Created by 1 on 2017/10/13.
 */

public class QQShareUtil {

    //==============================================================================================================

    /**
     * 分享链接
     * @param title 分享的标题
     * @param targetUrl  跳转的地址
     * @param content  分享的内容
     * @param iconUrl 图标地址
     * @param listener 分享回调
     * @return
     */
    public void shareUrlPassQQ(String title, String targetUrl, String content, String iconUrl,PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        Platform qq = ShareSDK.getPlatform (QQ.NAME);
        sp.setTitle(title);
        sp.setTitleUrl(targetUrl);
        sp.setText(content);
        sp.setImageUrl(iconUrl);
        qq.setPlatformActionListener(listener);
        qq.share(sp);
    }

    /**
     *  分享图片
     * @param urlOrPath  分享图片的url
     * @param listener  分享回调
     * @return
     */
    public void sharePicturePassQQ(String urlOrPath,PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        if(urlOrPath.contains("http")){
            sp.setImageUrl(urlOrPath);
        }else {
            sp.setImagePath(urlOrPath);
        }
        Platform qq = ShareSDK.getPlatform (QQ.NAME);
        qq.setPlatformActionListener(listener);
        qq.share(sp);
    }

    /**
     * 分享音频
     * @param title 分享的标题
     * @param content 分享的内容
     * @param iconUrl 图标地址
     * @param musicUrl 音乐地址
     * @param  listener  分享回掉
     * @return
     */
    public void shareMusicPassQQ(String title,String content, String iconUrl,String musicUrl,PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        sp.setTitle(title);
        sp.setText(content);
        if(iconUrl.contains("http")){
            sp.setImageUrl(iconUrl);
        }else {
            sp.setImagePath(iconUrl);
        }
        sp.setMusicUrl(musicUrl);
        Platform qq = ShareSDK.getPlatform (QQ.NAME);
        qq.setPlatformActionListener(listener);
        qq.share(sp);

    }

    //=========================================================================================================================
    /**
     * 分享QQ空间文字链接
     * @param title
     * @param targetUrl
     * @param content
     * @return
     */

    public void shareTextPassQQZone(String title, String targetUrl, String content, String imageUrl,PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        sp.setTitle(title);
        sp.setTitleUrl(targetUrl);
        sp.setText(content);

        if(imageUrl.contains("http")){
            sp.setImageUrl(imageUrl);
        }else {
            sp.setImagePath(imageUrl);
        }
        Platform qq = ShareSDK.getPlatform (QZone.NAME);
        qq.setPlatformActionListener(listener);
        qq.share(sp);
    }

    /**
     * 分享说说 图片
     * @param content
     * @param urlOrPath
     * @param listener 分享回调
     * @return
     */
    public  void shareTalkPassQQZone(String content, String urlOrPath,PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        sp.setText(content);
        if(urlOrPath.contains("http")){
            sp.setImageUrl(urlOrPath);
        }else {
            sp.setImagePath(urlOrPath);
        }
        Platform qq = ShareSDK.getPlatform (QZone.NAME);
        qq.setPlatformActionListener(listener);
        qq.share(sp);
    }


}
